#include <bits/stdc++.h>
using namespace std;
long long dp[2005];
int a[2005];
int c[2005];
int main() {
    freopen("color.in", "r", stdin);
    freopen("color.out", "w", stdout);
    int t;
    cin >> t;
    while(t--) {
        int n;
        cin >> n;
        for(int i=1; i<=n; i++) {
            cin >> a[i];
        }
        long long ans = 0;
        int mx = 0;
        int l, r;
        for(int i=1; i<=n; i++) {
            for(int j=i+1; j<=n; j++) {
                if(a[i]==a[j] && a[i] > mx) {
                    l=i, r=j;
                }
            }
        }
        ans+=mx;
        c[l] = c[r] = 1;

        cout << ans;
    }

    fclose(stdin);
    fclose(stdout);
    return 0;
}
